import re
from src.to_neo4j import dataToNeo4j
import json


class bianmingchaxun():
    def __init__(self):
        self.save_path = "../file/便民查询网/"
        self.Neo = dataToNeo4j()

    def name(self):
        with open(self.save_path + 'name.txt', encoding="utf8")as f:
            for line in f:
                temp = [i for i in line.replace("\n", '').split("\t") if i != '']
                name = temp[0].replace("，","_").replace("(","_").replace(")","")
                other = temp[1:]
                if self.Neo.query_node("食材", name=name) == 0:
                    self.Neo.create_node("食材", name)
                for element in other:
                    element =element.replace("，","_").replace("(","_").replace(")","")
                    print(name,element)
                    if self.Neo.query_node("食材别名", name=element) == 0:
                        self.Neo.create_node("食材别名", element)
                    status = self.Neo.relat_exists("食材", name, element, '食材对应别名')
                    if status:
                        self.Neo.create_relation_ship('食材', "食材别名", [[name, element]], '食材对应别名')



bianmingchaxun().name()
